package com.tedu.startbooksstore.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tedu.startbooksstore.pojo.dto.CategoryAddNewDTO;
import com.tedu.startbooksstore.pojo.vo.CategoryListItemVO;
import com.tedu.startbooksstore.service.ICategoryService;
import com.tedu.startbooksstore.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "03.分类模块")
@Slf4j
@RestController
@RequestMapping("/categories")
public class CategoryController {
    @Autowired
    ICategoryService categoryService;

    @ApiOperation("添加分类")
    @ApiOperationSupport(order = 310)
    @PostMapping("/add-new")
//    http://localhost:8080/categories/add-new
    public JsonResult<Void> add(CategoryAddNewDTO categoryAddNewDTO){
        log.debug("开始处理添加分类请求");
        categoryService.insert(categoryAddNewDTO);
        return JsonResult.ok();
    }


//    http://localhost:8080/categories
    @ApiOperation("分类列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("")
    public JsonResult< List<CategoryListItemVO>> list(){
        log.debug("开始处理分类列表请求");
        List<CategoryListItemVO> list = categoryService.list();
        return JsonResult.ok(list);
    }
}
